import { Component, Input, ViewEncapsulation, ChangeDetectionStrategy, ElementRef } from '@angular/core';
import { InputBoolean, TypeUtils } from '../core/api';

@Component({
  selector: '[lv-link]',
  templateUrl: './link.component.html',
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: {
    '[class.lv-link]': 'true',
    '[class.lv-link-primary]': 'lvType === "primary"',
    '[class.lv-link-normal]': 'lvType === "normal"',
    '[class.lv-link-disabled]': 'lvDisabled',
    '(click)': '_click($event)',
  },
})
export class LinkComponent {
  @Input() lvIcon: boolean | string = false;

  @Input() lvType: 'normal' | 'primary' = 'primary';

  @Input() @InputBoolean() lvDisabled: boolean = false;

  public typeUtils = TypeUtils;

  // 内部变量
  private _activeDom = this._element.nativeElement;

  constructor(private _element: ElementRef) {}

  _click($event: MouseEvent): void {
    if (this._activeDom.hasAttribute('disabled') || this.lvDisabled) {
      $event.stopPropagation();
      $event.preventDefault();
    }
  }
}
